local extension = Package("nshou_nx")
extension.extensionName = "tianshu"

Fk:loadTranslationTable{
  ["nshou_nx"] = "天书.年兽",
  ["tshunx"] = "年夕",
}


local U = require "packages/utility/utility"

local nwei = General(extension, "tshunx__nwei","wei",7)
nwei.hidden = true
local fange = fk.CreateTriggerSkill{
  name = "tshu__fange",
  anim_type = "defensive",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = player:drawCards(2,self.name)
    if math.abs(Fk:getCardById(cards[1]).number - Fk:getCardById(cards[2]).number) >= player.hp and data.from 
    and ((player.role == "rebel" and data.from.role ~= "rebel") 
    or ((player.role == "lord" or player.role == "loyalist") and (data.from.role ~= "lord" and data.from.role ~= "loyalist")))then
      room:damage({
        from = player,
        to = data.from,
        damage = 1,
        damageType = fk.NormalDamage,
        skillName = self.name,
      })
    end
  end,
}
nwei:addSkill(fange)
Fk:loadTranslationTable{
  ["tshunx__nwei"] = "年兽大魏",

  ["tshu__fange"] = "反戈",
  [":tshu__fange"] = "当你受到伤害后，你可以摸两张牌，然后若摸到的两张牌点数之差不小于你的体力值且伤害来源不为己方角色，你对伤害来源造成一点伤害",

  ["$tshu__fange"] = "前徒倒戈，攻于后以北。",
  ["~tshunx__nwei"] = " 魏兽威力，怎会倒下..",
}


local xwei = General(extension, "tshunx__xwei","wei",6)
xwei.hidden = true
local taoyuan = fk.CreateTriggerSkill{
  name = "tshu__taoyuan",
  anim_type = "defensive",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = player:drawCards(2,self.name)
    if (Fk:getCardById(cards[1]).suit ~= Fk:getCardById(cards[2]).suit) and data.from and not data.from:isKongcheng()
    and ((player.role == "rebel" and data.from.role ~= "rebel") 
    or ((player.role == "lord" or player.role == "loyalist") and (data.from.role ~= "lord" and data.from.role ~= "loyalist"))) then
      local cards2 = data.from:getCardIds("h")
      room:obtainCard(player, table.random(cards2), false, fk.ReasonPrey)
    end
  end,
}
xwei:addSkill(taoyuan)
Fk:loadTranslationTable{
  ["tshunx__xwei"] = "夕兽大魏",

  ["tshu__taoyuan"] = "饕怨",
  [":tshu__taoyuan"] = "当你受到伤害后，你可以摸两张牌，然后若摸到的两张牌花色不同且伤害来源不为己方角色，你随机获得伤害来源一张手牌",

  ["$tshu__taoyuan"] = "恩怨因果，报应不爽。",
  ["~tshunx__xwei"] = "大荒星陨，枭兽埋名。",
}

local nshu = General(extension, "tshunx__nshu","shu",4)
nshu.hidden = true
local siyao = fk.CreateTriggerSkill{
  name = "tshu__siyao",
  anim_type = "offensive",
  events = {fk.TargetSpecified,fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetSpecified then
      return target == player and player:hasSkill(self) and
      data.card and data.card.trueName == "slash" and data.firstTarget
    elseif event == fk.Damage then
      return target == player and player:hasSkill(self) and
      data.card and data.card.trueName == "slash" and data.to and data.to:isNude()
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.Damage then return true end
    local to = player.room:askForChoosePlayers(player, AimGroup:getAllTargets(data.tos), 1, 1, "#tshu__siyao-choose", self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      player.room:damage{
        from = player,
        to = player.room:getPlayerById(self.cost_data),
        damage = 1,
        skillName = self.name,
      }
    elseif event == fk.Damage then
      local cards = data.from:getCardIds("he")
      room:moveCardTo(table.random(cards),Card.DiscardPile,player,fk.ReasonDiscard)
    end
  end,
}
local hengsao = fk.CreateTriggerSkill{
  name = "tshu__hengsao",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    
    return target == player and player:hasSkill(self) and player.phase == Player.Play and #player:getCardIds("h") <= 6 and #player:getCardIds("h") >= 3
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player,"tshu__hengsao-phase",1)
  end,
}
local hengsao_target = fk.CreateTargetModSkill{
  name = "#tshu__hengsao_target",
  extra_target_func = function(self, player, skill, card)
    if  skill.trueName == "slash_skill" and player:getMark("tshu__hengsao-phase") > 0  then
        return 1
    end
  end,
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:getMark("tshu__hengsao-phase") > 0 then
      return 1
    end
    return 0
  end,
}
hengsao:addRelatedSkill(hengsao_target)
nshu:addSkill(siyao)
nshu:addSkill(hengsao)
Fk:loadTranslationTable{
  ["tshunx__nshu"] = "年兽大蜀",

  ["tshu__siyao"] = "撕咬",
  [":tshu__siyao"] = "当你使用【杀】指定目标后，你可以对其中一名目标造成一点伤害；当你使用的【杀】造成伤害后，受伤角色随机弃置一张牌。",
  ["tshu__hengsao"] = "横扫",
  [":tshu__hengsao"] = "锁定技，你的出牌阶段开始时，若你的手牌数在3~6之间，你本阶段可使用【杀】的次数+1,使用【杀】可指定的目标数+1",
  ["#tshu__siyao-choose"] = "撕咬：选择的其中一名角色造成一点伤害。",

  ["$tshu__siyao"] = "撕裂破碎，吞咬河山。",
  ["$tshu__hengsao"] = "横扫天下，平定四方。",
  ["~tshunx__nshu"] = "蜀兽威力，怎会倒下..",
}

local xshu = General(extension, "tshunx__xshu","shu",5)
xshu.hidden = true
local lizhan = fk.CreateTriggerSkill{
  name = "tshu__lizhan",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart,fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Play
    elseif event == fk.CardUseFinished and player:hasSkill(self) and target == player then
      local cardlist = data.card:isVirtual() and data.card.subcards or {data.card.id}
      return #player.room.logic:getEventsOfScope(GameEvent.UseCard, 3, function(e)
        local use = e.data[1]
        return use.from == player.id and use.card.trueName == "slash"
      end, Player.HistoryTurn) == 1 and data.card.trueName == "slash" and table.every(cardlist, function (id)
        return player.room:getCardArea(id) == Card.Processing
      end)
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.EventPhaseStart then return true end
    local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#tshu__lizhan-card:::"..data.card:toLogString(), self.name, true)
    if #to > 0 then
      self.cost_data = to[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseStart then
      local cards = player.room:getCardsFromPileByRule("slash", 2,"disicardPile")
      if #cards > 0 then
        player.room:obtainCard(player, cards[1], true, fk.ReasonJustMove)
      end
      if #cards > 1 then
        player.room:obtainCard(player, cards[2], true, fk.ReasonJustMove)
      end
    elseif event == fk.CardUseFinished then
      room:moveCards({
        to = self.cost_data,
        toArea = Card.PlayerHand,
        ids = room:getSubcardsByRule(data.card, { Card.Processing }),
        proposer = player.id,
        moveReason = fk.ReasonGive,
      })
    end
  end,
}
xshu:addSkill("os_ex__paoxiao")
xshu:addSkill(lizhan)
Fk:loadTranslationTable{
  ["tshunx__xshu"] = "夕兽大蜀",

  ["tshu__lizhan"] = "励战",
  [":tshu__lizhan"] = "锁定技，你的出牌阶段开始时，你从弃牌堆获得两张【杀】；你每回合第一张【杀】结算后，你可以将其交给一名其他角色。",
  ["#tshu__lizhan-card"] = "励战：你可以将 %arg 交给一名其他角色。",

  ["$tshu__lizhan"] = "身经百战，大蜀万丈。",
  ["$os_ex__paoxiao_tshunx__xshu"] = "气惊六合。虎啸八方！",
  ["~tshunx__xshu"] = "折翼沙场，大业一梦...",
}

local nwu = General(extension, "tshunx__nwu","wu",5,5,General.Female)
nwu.hidden = true
local zhuyan = fk.CreateTriggerSkill{
  name = "tshu__zhuyan",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Draw
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = table.random(room.draw_pile,4)
      if #ids > 0 then
        for _, cid in ipairs(ids) do
          room:obtainCard(player, cid, false, fk.ReasonPrey)
        end
      end
    return true
  end,
}
nwu:addSkill(zhuyan)
nwu:addSkill("xiaoji")
Fk:loadTranslationTable{
  ["tshunx__nwu"] = "年兽大吴",

  ["tshu__zhuyan"] = "朱颜",
  [":tshu__zhuyan"] = "锁定技，摸牌阶段，你改为随机获得牌堆中的四张牌。",

  ["$tshu__zhuyan"] = "朱颜佳色，倾倒众生。",
  ["$xiaoji_tshunx__nwu"] = "这些装备，还是给我更好。",
  ["~tshunx__nwu"] = "吴兽威力，怎会倒下..",
}

local xwu = General(extension, "tshunx__xwu","wu",4,4,General.Female)
xwu.hidden = true
xwu:addSkill("mingzhe")
xwu:addSkill("ol_ex__tianxiang")
Fk:loadTranslationTable{
  ["tshunx__xwu"] = "夕兽大吴",

  ["$mingzhe_tshunx__xwu"] = "赤诚之心，天地可鉴。",
  ["$ol_ex__tianxiang_tshunx__xwu"] = "携红为秉，否极泰来。",
  ["~tshunx__xwu"] = "爆竹惊魂，落花流水。",
}

local nqun = General(extension, "tshunx__nqun","qun",5)
nqun.hidden = true
local qunxiang = fk.CreateTriggerSkill{
  name = "tshu__qunxiang",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and target == player and (player.phase == Player.Start or player.phase == Player.Finish) and (not player:prohibitUse(Fk:cloneCard("archery_attack")) or not player:prohibitUse(Fk:cloneCard("savage_assault")) )
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choices = {}
    if not player:prohibitUse(Fk:cloneCard("archery_attack")) then
      table.insertIfNeed(choices,"archery_attack")
    end
    if not player:prohibitUse(Fk:cloneCard("savage_assault")) then
      table.insertIfNeed(choices,"savage_assault")
    end
    local choice = room:askForChoice(player,choices,self.name,nil,false,{"archery_attack","savage_assault"})
    U.askForUseVirtualCard(room, player,choice, nil, self.name)
  end,
}
local tanshi = fk.CreateTriggerSkill{
  name = "tshu__tanshi",
  anim_type = "drawcard",
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|club,spade",
    }
    room:judge(judge)
    if judge.card.color == Card.Black and not player.dead then
      if player:isWounded() then
        room:recover({
          who = player,
          num = 1,
          recoverBy = player,
          skillName = self.name
          })
      else
        player:drawCards(1,self.name)
      end
    end
  end,
}
nqun:addSkill(qunxiang)
nqun:addSkill(tanshi)
Fk:loadTranslationTable{
  ["tshunx__nqun"] = "年兽大群",

  ["tshu__qunxiang"] = "群响",
  [":tshu__qunxiang"] = "锁定技，你的准备阶段或结束阶段，你可以视为使用一张【万箭齐发】或【南蛮入侵】。",
  ["tshu__tanshi"] = "贪食",
  [":tshu__tanshi"] = "当你造成伤害后，你可以进行判定，若判定结果为黑色，你回复一点体力（若满血则改为摸一张牌）。",

  ["$tshu__qunxiang"] = "合群之力，响动四海。",
  ["$tshu__tanshi"] = "这么多好吃的，都是我的了。",
  ["~tshunx__nqun"] = "群兽之力，怎会倒下..",

}

local xqun = General(extension, "tshunx__xqun","qun",5)
xqun.hidden = true
local shouxi = fk.CreateTriggerSkill{
  name = "tshu__shouxi",
  anim_type = "control",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(self) and target == player and data.card.type == Card.TypeTrick and data.card.color == Card.Black
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|heart,diamond,club,spade",
    }
    room:judge(judge)
    if judge.card.color == Card.Black  then
      local tar = {}
      for _, p in ipairs(room.alive_players) do
        if (player.role == "rebel" and p.role ~= "rebel") 
    or ((player.role == "lord" or player.role == "loyalist") and (p.role ~= "lord" and p.role ~= "loyalist")) then
          table.insertIfNeed(tar,p)
        end
      end
      table.shuffle(tar)
      if #tar > 0 then
        player.room:damage{
          from = player,
          to = tar[1],
          damage = 1,
          skillName = self.name,
        }
      end
    elseif judge.card.color == Card.Red and not player.dead then
      room:obtainCard(player, judge.card.id, false, fk.ReasonPrey)
    end
  end,
}
xqun:addSkill("juxiang")
xqun:addSkill(shouxi)
Fk:loadTranslationTable{
  ["tshunx__xqun"] = "夕兽大群",

  ["tshu__shouxi"] = "兽袭",
  [":tshu__shouxi"] = "当你使用黑色锦囊牌时，你可以进行判定：若为黑色，你随机对一名敌方角色造成一点伤害；若为红色，你获得判定牌。",

  ["$tshu__shouxi"] = "磨牙砺爪，一击而就。",
  ["$juxiang_tshunx__xqun"] = "山神打鼓，百兽狂奔。",
  ["~tshunx__xqun"] = "茕茕困兽，东走西顾。",

}



local pucong = General(extension, "tshunx__pucong","qun",3)
pucong.hidden = true

local indulgenceSkill = fk.CreateActiveSkill{
  name = "tshu__indulgence_skill",
  mod_target_filter = function(self, to_select, selected, user, card)
    if not Fk:currentRoom() then return user ~= to_select end
    return user ~= to_select
  end,
  target_filter = function(self, to_select, selected, user, card)
    if #selected >= self.target_num then return false end
    if user == to_select then return false end
    return self:modTargetFilter(to_select, selected, user, card)
  end,
  target_num = 1,
  
  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local judge = {
      who = to,
      reason = "indulgence",
      pattern = ".|.|heart",
    }
    room:judge(judge)
    local result = judge.card
    if result.suit == Card.Heart then
      to:skip(Player.Play)
    end
    self:onNullified(room, effect)
  end,
  on_nullified = function(self, room, effect)
    room:moveCards{
      ids = room:getSubcardsByRule(effect.card, { Card.Processing }),
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonUse
    }
  end,
}
Fk:addSkill(indulgenceSkill)


local supplyShortageSkill = fk.CreateActiveSkill{
  name = "tshu__supply_shortage_skill",
  distance_limit = 1,
  mod_target_filter = function(self, to_select, _, user, card, distance_limited)
    if not Fk:currentRoom() then return user ~= to_select end
    -- 先检查ID是否有效
    if not table.contains(Fk:currentRoom().alive_players, to_select) or
       not table.contains(Fk:currentRoom().alive_players, user) then
      return false
    end
    local player = Fk:currentRoom():getPlayerById(to_select)
    local from = Fk:currentRoom():getPlayerById(user)
    return from ~= player and not (distance_limited and not self:withinDistanceLimit(from, false, card, player))
  end,
  target_filter = function(self, to_select, selected, user, card, extra_data)
    if #selected >= self.target_num then return false end
    if user == to_select then return false end
    local count_distances = not (extra_data and extra_data.bypass_distances)
    return self:modTargetFilter(to_select, selected, user, card, count_distances)
  end,
  target_num = 1,

  on_effect = function(self, room, effect)
    local to = room:getPlayerById(effect.to)
    local judge = {
      who = to,
      reason = "supply_shortage",
      pattern = ".|.|club",
    }
    room:judge(judge)
    local result = judge.card
    if result.suit == Card.Club then
      to:skip(Player.Draw)
    end
    self:onNullified(room, effect)
  end,
  on_nullified = function(self, room, effect)
    room:moveCards{
      ids = room:getSubcardsByRule(effect.card, { Card.Processing }),
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonUse
    }
  end,
}


Fk:addSkill(supplyShortageSkill)
local xiongshou = fk.CreateTriggerSkill{
  name = "tshu__xiongshou",
  frequency = Skill.Compulsory,
  events = {fk.CardEffecting,fk.DrawNCards,fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardEffecting then
      return player:hasSkill(self) and target == player and (data.card.trueName == "indulgence" or data.card.trueName == "supply_shortage")
    elseif event == fk.DrawNCards then
      return target == player and player:hasSkill(self)
    elseif event == fk.EventPhaseStart then
      return target == player and player:hasSkill(self) and player.phase == Player.Finish
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.DrawNCards then
      data.n = data.n + 1
    elseif event == fk.EventPhaseStart then
      if not player.dead then
        player:drawCards(1,self.name)
      end
    elseif event == fk.CardEffecting then
      local card = data.card:clone()
      local c = table.simpleClone(data.card)
      for k, v in pairs(c) do
        card[k] = v
      end
      if data.card.trueName == "indulgence" then
        local ogri_skill = Fk.skills["indulgence_skill"]
        card.skill = (card.skill == ogri_skill) and indulgenceSkill or ogri_skill
        data.card = card
      elseif data.card.trueName == "supply_shortage" then
        local ogri_skill = Fk.skills["supply_shortage_skill"]
        card.skill = (card.skill == ogri_skill) and supplyShortageSkill or ogri_skill
        data.card = card
      end
    end
  end,
}
local xisheng = fk.CreateTriggerSkill{
  name = "tshu__xisheng",
  anim_type = "support",
  events = {fk.Death},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self.name, false, true)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room.alive_players) do
      if (player.role == "rebel" and p.role == "rebel") 
      or ((player.role == "lord" or player.role == "loyalist") and (p.role == "lord" or p.role == "loyalist")) then
        if math.random(1,2) == 1 and p:isWounded() then
          room:recover({
            who = p,
            num = 1,
            recoverBy = player,
            skillName = self.name
            })
          elseif not p.dead then
          p:drawCards(1,self.name)
        end
      end
    end
  end,
}
pucong:addSkill(xiongshou)
pucong:addSkill(xisheng)
Fk:loadTranslationTable{
  ["tshunx__pucong"] = "年兽仆从",

  ["tshu__xiongshou"] = "凶兽",
  [":tshu__xiongshou"] = "锁定技，你判定区的【乐不思蜀】或【兵粮寸断】判定效结果反转；摸牌阶段你多摸一张牌，结束阶段你摸一张牌。",
  ["tshu__xisheng"] = "牺牲",
  [":tshu__xisheng"] = "锁定技，你死亡时，所有友方角色随机摸一张牌或回复一点体力。",

  ["$tshu__xiongshou"] = "这些，别想阻止我！",
  ["$tshu__xisheng"] = "请不要辜负所托。",
  ["~tshunx__pucong"] = "下次，你就没用这样的好运了..",

}




Fk:loadTranslationTable{
  ["tshusx"] = "生肖",
}


local tu = General(extension, "tshusx__tu", "wei", 3, 3, General.Female)
tu.hidden = true
local ji = General(extension, "tshusx__ji", "wei", 3, 3, General.Male)
ji.hidden = true
local niu = General(extension, "tshusx__niu", "wei", 1, 5, General.Male)
niu.hidden = true

local she = General(extension, "tshusx__she", "shu", 3, 3, General.Female)
she.hidden = true
local long = General(extension, "tshusx__long", "shu", 4, 4, General.Male)
long.hidden = true
local gou = General(extension, "tshusx__gou", "shu", 4, 4, General.Male)
gou.hidden = true

local hou = General(extension, "tshusx__hou", "wu", 3, 3, General.Male)
hou.hidden = true
local hu = General(extension, "tshusx__hu", "wu", 4, 4, General.Male)
hu.hidden = true
local yang = General(extension, "tshusx__yang", "wu", 3, 3, General.Male)
yang.hidden = true

local ma = General(extension, "tshusx__ma", "qun", 4, 4, General.Male)
ma.hidden = true
local shu = General(extension, "tshusx__shu", "qun", 3, 3, General.Male)
shu.hidden = true
local zhu = General(extension, "tshusx__zhu", "qun", 5, 5, General.Male)
zhu.hidden = true







Fk:loadTranslationTable{
  ["tshusx__shu"] = "子鼠",
  ["~tshusx__shu"] = "油米全没了……",
  ["tshusx__niu"] = "丑牛",
  ["~tshusx__niu"] = "请将我埋于此地吧……",
  ["tshusx__hu"] = "寅虎",
  ["~tshusx__hu"] = "百兽之王，也有终老……",
  ["tshusx__tu"] = "卯兔",
  ["~tshusx__tu"] = "这灾祸……是躲不过了……",
  ["tshusx__long"] = "辰龙",
  ["~tshusx__long"] = "龙威不再，龙鳞已落……",
  ["tshusx__she"] = "巳蛇",
  ["~tshusx__she"] = "我的毒液……失效了……",
  ["tshusx__ma"] = "午马",
  ["~tshusx__ma"] = "马有失蹄啊……",
  ["tshusx__yang"] = "未羊",
  ["~tshusx__yang"] = "看不到青草翠绿时……",
  ["tshusx__hou"] = "申猴",
  ["~tshusx__hou"] = "这仙桃……无用了……",
  ["tshusx__ji"] = "酉鸡",
  ["~tshusx__ji"] = "杀鸡取卵，不可取呀。",
  ["tshusx__gou"] = "戌狗",
  ["~tshusx__gou"] = "不能守护家园了",
  ["tshusx__zhu"] = "亥猪",
  ["~tshusx__zhu"] = "噢，果然，还是吃太多了。",
}

local zishu = fk.CreateActiveSkill{
  name = "tshu__zishu",
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    local target = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and target:getHandcardNum() > Self:getHandcardNum()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local c = room:askForCardChosen(player, target, "h", self.name)
    room:obtainCard(player, c, false, fk.ReasonPrey)
    local targets, tos = {}, {}
    while true do
      targets = table.filter(room:getOtherPlayers(player), function(p)
          return p:getHandcardNum() > player:getHandcardNum()
      end)
      if #targets == 0 then break end
      tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#tshu__zishu-choose", self.name, true)
      if #tos ~= 1 then break end
      c = room:askForCardChosen(player, room:getPlayerById(tos[1]), "h", self.name)
      room:obtainCard(player, c, false, fk.ReasonPrey)
    end
  end,
}
shu:addSkill(zishu)

Fk:loadTranslationTable{
  ["tshu__zishu"] = "子鼠",
  [":tshu__zishu"] = "出牌阶段限一次，获得一名手牌数大于你的角色一张手牌直到你的手牌数成为全场最大。",
  ["#tshu__zishu-choose"] = "子鼠：指定一名手牌数大于你的角色，获得其一张手牌。",
  ["$tshu__zishu"] = "这些牌都归我吧！"
}

local chouniu = fk.CreateTriggerSkill{
  name = "tshu__chouniu",
  anim_type = "support",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
      and player.phase == Player.Finish
      and #table.filter(player.room:getOtherPlayers(player), function(p) return p.hp < player.hp end) == 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:recover{
    who = player,
    num = 1,
    recoverBy = player,
    skillName = self.name
    }
  end,
}

niu:addSkill(chouniu)

Fk:loadTranslationTable{
  ["tshu__chouniu"] = "丑牛",
  [":tshu__chouniu"] = "锁定技，结束阶段，若你的体力值为全场最小，你回复1点体力。",
  ["$tshu__chouniu"] = "牛角之歌，自保足矣。"
}



local yinhuh = fk.CreateActiveSkill{
  name = "tshu__yinhuh",
  anim_type = "offensive",
  card_num = 1,
  target_num = 1,
  can_use = function(self, player)
    return not player:isNude() and player:getMark("disable_yinhuh-turn") == 0
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 0 and not Self:prohibitDiscard(Fk:getCardById(to_select)) then
      local mark = Self:getTableMark( "tshu__yinhuh-phase")
      return not table.contains(mark, Fk:getCardById(to_select).type)
    end
  end,
  target_filter = function(self, to_select, selected)
    return to_select ~= Self.id
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    local mark = player:getTableMark( "tshu__yinhuh-phase")
    table.insert(mark, Fk:getCardById(effect.cards[1]).type)
    room:setPlayerMark(player, "tshu__yinhuh-phase", mark)
    room:throwCard(effect.cards, self.name, player)
    if not target.dead then
      room:damage{
        from = player,
        to = target,
        damage = 1,
        skillName = self.name,
      }
    end
  end,
}
local yinhuh_trigger = fk.CreateTriggerSkill{
  name = "#yinhuh_trigger",
  mute = true,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    return data.damage and data.damage.skillName == "tshu__yinhuh" and data.damage.from
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "disable_yinhuh-turn", 1)
  end,
}

yinhuh:addRelatedSkill(yinhuh_trigger)
hu:addSkill(yinhuh)

Fk:loadTranslationTable{
  ["tshu__yinhuh"] = "寅虎",
  [":tshu__yinhuh"] = "出牌阶段每种花色的牌限一次，你可以弃置一张牌，对一名其他角色造成1点伤害。若其因此进入濒死状态，此技能失效直到回合结束。",
  ["#yinhuh_trigger"] = "寅虎-失效",
  ["$tshu__yinhuh"] = "尝尝我的厉害吧！",
}

local maotu = fk.CreateTriggerSkill{
  name = "tshu__maotu",
  anim_type = "special",
  frequency = Skill.Compulsory,
  events = {fk.Deathed},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@tshu__maotu", 1)
  end,

  refresh_events = {fk.EventPhaseStart, fk.Death},
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@tshu__maotu") ~= 0 and (event == fk.Death or player.phase == Player.Play)
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@tshu__maotu", 0)
  end,
}
local maotu_prohibit = fk.CreateProhibitSkill{
  name = "#tshu__maotu_prohibit",
  mute = true,
  frequency = Skill.Compulsory,
  is_prohibited = function(self, from, to, card)
    return to:hasSkill(self) and to:getMark("@@tshu__maotu") ~= 0 and from ~= to and from.hp >= to.hp
  end,
}

maotu:addRelatedSkill(maotu_prohibit)
tu:addSkill(maotu)

Fk:loadTranslationTable{
  ["tshu__maotu"] = "卯兔",
  [":tshu__maotu"] = "锁定技，其他角色死亡时，你不能成为其他角色使用牌的目标直到你的下个出牌阶段开始时。",
  ["@@tshu__maotu"] = "卯兔",
  ["$tshu__maotu"] = "想抓到我？不可能！",
}

local chenlong = fk.CreateActiveSkill{
  name = "tshu__chenlong",
  anim_type = "offensive",
  frequency = Skill.Limited,
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  interaction = function()
    return UI.Spin {
      from = 1,
      to = Self.hp,
    }
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select).role ~= Self.role
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    room:loseHp(player, self.interaction.data, self.name)
    room:damage{
      from = player,
      to = target,
      damage = self.interaction.data,
      skillName = self.name,
    }
  end,
}
local chenlong_trigger = fk.CreateTriggerSkill{
  name = "#tshu__chenlong_trigger",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.EnterDying},
  can_trigger = function(self, event, target, player, data)
    local skillEvent = player.room.logic:getCurrentEvent().parent.parent
    if #skillEvent.data < 3 then return false end
    return skillEvent.data[3] == "tshu__chenlong" and target == player and player:hasSkill(self) and not data.damage and not target.dead and target.hp < 1
  end,
  on_use = function(self, event, target, player, data)
    player.room:recover{
      who = player,
      num = 1-player.hp,
      recoverBy = player,
      skillName = self.name
    }
    if not player.dead then
      player.room:changeMaxHp(player, -1)
    end
  end,
}

chenlong:addRelatedSkill(chenlong_trigger)
long:addSkill(chenlong)

Fk:loadTranslationTable{
  ["tshu__chenlong"] = "辰龙",
  [":tshu__chenlong"] = "限定技，你可以失去至多5点体力，对一名其他角色造成等量伤害。若你因此进入濒死状态，你回复体力至1点，减1点体力上限。",
  ["#tshu__chenlong_trigger"] = "辰龙-回复",
  ["$tshu__chenlong"] = "龙怒的威力，不是你所能承受的。",
}

local sishe = fk.CreateTriggerSkill{
  name = "tshu__sishe",
  anim_type = "masochism",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return data.to == player and data.to:hasSkill(self) and data.from and not data.from.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = data.from
    if from and not from.dead
      then room:doIndicate(player.id, {from.id})
    end
    room:damage{
      from = player,
      to = from,
      damage = data.damage,
      skillName = self.name,
    }
  end
}

she:addSkill(sishe)

Fk:loadTranslationTable{
  ["tshu__sishe"] = "巳蛇",
  [":tshu__sishe"] = "当你受到伤害后，你可以对伤害来源造成等量伤害。",
  ["$tshu__sishe"] = "伤我者，一一奉还。",
}

local wuma = fk.CreateTriggerSkill{
  name = "tshu__wuma",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.BeforeTurnOver, fk.EventPhaseSkipping, fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      return (event == fk.TargetConfirmed and data.card.type == Card.TypeTrick) or event ~= fk.TargetConfirmed
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.TargetConfirmed then
      player.room:notifySkillInvoked(player, self.name, "drawcard")
      player:broadcastSkillInvoke(self.name)
      player:drawCards(1, self.name)
    else
      player.room:notifySkillInvoked(player, self.name, "defensive")
      player:broadcastSkillInvoke(self.name)
      return true
    end
  end,
}

ma:addSkill(wuma)

Fk:loadTranslationTable{
  ["tshu__wuma"] = "午马",
  [":tshu__wuma"] = "锁定技，你翻面前，取消之；你的阶段被跳过前，取消之；当你成为其他角色锦囊牌的目标后，你摸一张牌。",
  ["$tshu__wuma"] = "有我在，必成功！",
}

local weiyang = fk.CreateActiveSkill{
  name = "tshu__weiyang",
  anim_type = "support",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = function(self, to_select, selected, targets)
    if #selected == 0 then return
      not Self:prohibitDiscard(Fk:getCardById(to_select))
    else return
      table.every(selected, function(id) return Fk:getCardById(to_select):getTypeString() ~= Fk:getCardById(id):getTypeString() end)
      and not Self:prohibitDiscard(Fk:getCardById(to_select))
    end
  end,
  target_filter = function(self, to_select, selected, cards)
    return #selected < #cards and Fk:currentRoom():getPlayerById(to_select):isWounded()
  end,
  on_use = function(self, room, effect)
    local from = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, from, from)
    if from:isAlive() and from:isWounded() then
      for _, id in ipairs(effect.tos) do
        room:recover({
          who = room:getPlayerById(id),
          num = 1,
          recoverBy = from,
          skillName = self.name
        })
      end
    end
  end,
}

yang:addSkill(weiyang)

Fk:loadTranslationTable{
  ["tshu__weiyang"] = "未羊",
  [":tshu__weiyang"] = "出牌阶段限一次，你可以弃置任意张类别不同的牌，令至多等量角色各回复1点体力。",
  ["$tshu__weiyang"] = "共享绵泽，同甘共苦。",
}

local shenhou = fk.CreateTriggerSkill{
  name = "tshu__shenhou",
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    player.room:notifySkillInvoked(player, self.name, "defensive")
    local judge = {
      who = player,
      reason = self.name,
      pattern = ".|.|heart,diamond",
    }
    player.room:judge(judge)
    if judge.card.color == Card.Red then
      table.insertIfNeed(data.nullifiedTargets, player.id)
      return true
    end
  end,
}

hou:addSkill(shenhou)

Fk:loadTranslationTable{
  ["tshu__shenhou"] = "申猴",
  [":tshu__shenhou"] = "当你成为【杀】的目标后，你可以判定。若结果为红色，你令之对你无效。",
  ["$tshu__shenhou"] = "百般变化，真假难辨！",
}

local youji = fk.CreateTriggerSkill{
  name = "tshu__youji",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.DrawNCards},
  on_use = function(self, event, target, player, data)
    data.n = data.n + math.min(player.room:getTag("RoundCount"), 5)
  end,
}

ji:addSkill(youji)

Fk:loadTranslationTable{
  ["tshu__youji"] = "酉鸡",
  [":tshu__youji"] = "锁定技，摸牌阶段，你多摸X张牌（X为游戏轮数，至多为5）。",
  ["$tshu__youji"] = "鸡豚之息，虽微渐厚！",
}

local xugouh = fk.CreateTriggerSkill{
  name = "tshu__xugouh",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.TargetConfirmed, fk.AfterCardUseDeclared},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.card.trueName == "slash" and data.card.color == Card.Red
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.TargetConfirmed then
      player.room:notifySkillInvoked(player, self.name, "defensive")
      player:broadcastSkillInvoke(self.name)
      table.insertIfNeed(data.nullifiedTargets, player.id)
    else
      player.room:notifySkillInvoked(player, self.name, "offensive")
      player:broadcastSkillInvoke(self.name)
      data.additionalDamage = (data.additionalDamage or 0) + 1
    end
  end,
}
local xugouh_targetmod = fk.CreateTargetModSkill{
  name = "#xugouh_targetmod",
  frequency = Skill.Compulsory,
  residue_func = function(self, player, skill, scope)
    if player:hasSkill(self) and skill.trueName == "slash_skill" then
      return 1
    end
  end,
}





xugouh:addRelatedSkill(xugouh_targetmod)
gou:addSkill(xugouh)

Fk:loadTranslationTable{
  ["tshu__xugouh"] = "戌狗",
  [":tshu__xugouh"] = "锁定技，红色【杀】对你无效；你使用的红色【杀】无距离限制且造成的伤害+1。",
  ["$tshu__xugouh"] = "驱邪吠恶，遇凶斩杀。",
}

local haizhu = fk.CreateTriggerSkill{
  name = "tshu__haizhu",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.AfterCardsMove then
        local ids = {}
        local room = player.room
        for _, move in ipairs(data) do
          if move.toArea == Card.DiscardPile then
            if move.moveReason == fk.ReasonDiscard and move.from and move.from ~= player.id then
              for _, info in ipairs(move.moveInfo) do
                if (info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip) and
                Fk:getCardById(info.cardId).color == Card.Black and
                room:getCardArea(info.cardId) == Card.DiscardPile then
                  table.insertIfNeed(ids, info.cardId)
                end
              end
            end
          end
        end
        ids = U.moveCardsHoldingAreaCheck(room, ids)
        if #ids > 0 then
          self.cost_data = ids
          return true
        end
      else return
        target == player and player.phase == Player.Start and
        table.every(player.room:getOtherPlayers(player), function(p) return p:getHandcardNum() <= player:getHandcardNum() end)
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      player.room:notifySkillInvoked(player, self.name, "drawcard")
      player:broadcastSkillInvoke(self.name)
      local ids = table.simpleClone(self.cost_data)
      if #ids > 0 then
        room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonPrey, self.name)
      end
    else
      player.room:notifySkillInvoked(player, self.name, "negtive")
      room:loseHp(player, 1, self.name)
    end
  end,
}

zhu:addSkill(haizhu)

Fk:loadTranslationTable{
  ["tshu__haizhu"] = "亥猪",
  [":tshu__haizhu"] = "锁定技，其他角色的黑色牌因弃置进入弃牌堆后，你获得之；准备阶段，若你的手牌数为全场最大，你失去1点体力。",
  ["$tshu__haizhu"] = "这些都归我吧。",
}




return extension